home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / door / twview93.zip / BASEPATH.INC < prev    next >
Text File  |  1992-04-29  |  1KB  |  41 lines

  1. function FixPath( start, finish : sector ) : integer;
  2. { Adjusts Distances from start up to point were finish is entered;
  3. returns length of path. }
  4. var
  5.   s : sector;
  6.   breadth : queue;
  7.   daddy, sonny : sector;
  8.   i : warpindex;
  9.   done : boolean;
  10. begin
  11.   for s := 1 to maxSector do
  12.     Distances[s].d := -1;
  13.   breadth.front := 0;
  14.   enqueue( breadth, start, start );
  15.   repeat
  16.       serve( breadth, daddy, sonny );
  17.       if (Distances[ sonny ].d = -1) then {haven't hit him before:}
  18.         begin
  19.           distances[ sonny ].d := distances[ daddy ].d + 1;
  20.           distances[ sonny ].s := daddy;
  21.           if (space.sectors[sonny].etc and avoid) = Nothing then
  22.             with space.sectors[ sonny ] do if number > 0 then
  23.               for i := 1 to number do
  24.                 enqueue( breadth, sonny, data[ i ] );
  25.           done := sonny = finish;
  26.         end; {if}
  27.   until done or (breadth.front = 0);
  28.   for s := 1 to maxSector do
  29.     if distances[s].d = -1 then distances[s].d := maxint;
  30.   FixPath := distances[ finish ].d;
  31. end; {FixPath}
  32.  
  33. procedure PrintPath( var home : sector; sec : sector );
  34. var
  35.   dummy : text;
  36. begin
  37.   if home <> sec then
  38.     PrintPath( home, distances[ sec ].s );
  39.   displaySector( sec, 'Dist', error, false, dummy )
  40. end;
  41.